home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / ext / events / telepathy_status.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  6KB  |  143 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import os
  5. import sys
  6. if os.name == 'nt' or sys.platform == 'darwin':
  7.     from quodlibet.plugins import PluginNotSupportedError
  8.     raise PluginNotSupportedError
  9. import dbus
  10. from gi.repository import Gtk
  11. from quodlibet.parse._pattern import Pattern
  12. from quodlibet.qltk.entry import UndoEntry
  13. from quodlibet import util
  14. from quodlibet import qltk
  15. from quodlibet.plugins.events import EventPlugin
  16. from quodlibet.plugins import PluginConfigMixin
  17. from quodlibet.util.dprint import print_d
  18. AM_PATH = '/org/freedesktop/Telepathy/AccountManager'
  19. AM_NAME = 'org.freedesktop.Telepathy.AccountManager'
  20. AM_IFACE = 'org.freedesktop.Telepathy.AccountManager'
  21. AC_IFACE = 'org.freedesktop.Telepathy.Account'
  22. PROPS_IFACE = 'org.freedesktop.DBus.Properties'
  23. CONN_PRESENCE_TYPE_AVAILABLE = 2
  24.  
  25. is_valid_presence_type = lambda x: x not in (0, 7, 8)
  26.  
  27. def get_active_account_paths():
  28.     bus = dbus.SessionBus()
  29.     bus_object = bus.get_object(AM_NAME, AM_PATH)
  30.     bus_iface = dbus.Interface(bus_object, dbus_interface = PROPS_IFACE)
  31.     return bus_iface.Get(AM_IFACE, 'ValidAccounts')
  32.  
  33.  
  34. def set_accounts_requested_presence(paths, message):
  35.     bus = dbus.SessionBus()
  36.     for path in paths:
  37.         bus_object = bus.get_object(AM_NAME, path)
  38.         bus_iface = dbus.Interface(bus_object, dbus_interface = PROPS_IFACE)
  39.         (presence_type, status) = bus_iface.Get(AC_IFACE, 'CurrentPresence')[:2]
  40.         if not is_valid_presence_type(presence_type):
  41.             presence_type = dbus.UInt32(CONN_PRESENCE_TYPE_AVAILABLE)
  42.         value = dbus.Struct([
  43.             presence_type,
  44.             status,
  45.             message])
  46.         bus_iface.Set(AC_IFACE, 'RequestedPresence', value)
  47.     
  48.  
  49.  
  50. class TelepathyStatusPlugin(EventPlugin, PluginConfigMixin):
  51.     PLUGIN_ID = 'Telepathy Status'
  52.     PLUGIN_NAME = _('Telepathy Status Messages')
  53.     PLUGIN_DESC = _('Updates all Telepathy-based IM accounts (as configured in Empathy etc) with a status message based on current song.')
  54.     PLUGIN_ICON = Gtk.STOCK_CONNECT
  55.     PLUGIN_VERSION = '0.3'
  56.     DEFAULT_PAT = '\xe2\x99\xab <~artist~title> \xe2\x99\xab'
  57.     DEFAULT_PAT_PAUSED = '<~artist~title> [%s]' % _('paused')
  58.     CFG_STATUS_SONGLESS = 'no_song_text'
  59.     CFG_LEAVE_STATUS = 'leave_status'
  60.     CFG_PAT_PLAYING = 'playing_pattern'
  61.     CFG_PAT_PAUSED = 'paused_pattern'
  62.     
  63.     def _set_status(self, text):
  64.         print_d('Setting status to "%s"...' % text)
  65.         self.status = text
  66.         
  67.         try:
  68.             accounts = get_active_account_paths()
  69.             set_accounts_requested_presence(accounts, text)
  70.         except dbus.DBusException:
  71.             print_d('...but setting failed')
  72.             util.print_exc()
  73.  
  74.  
  75.     
  76.     def plugin_on_song_started(self, song):
  77.         self.song = song
  78.         pat_str = self.config_get(self.CFG_PAT_PLAYING, self.DEFAULT_PAT)
  79.         pattern = Pattern(pat_str)
  80.         status = pattern.format(song) if song else self.config_get(self.CFG_STATUS_SONGLESS, '')
  81.         self._set_status(status)
  82.  
  83.     
  84.     def plugin_on_paused(self):
  85.         pat_str = self.config_get(self.CFG_PAT_PAUSED, self.DEFAULT_PAT_PAUSED)
  86.         pattern = Pattern(pat_str)
  87.         self.status = pattern.format(self.song) if self.song else ''
  88.         self._set_status(self.status)
  89.  
  90.     
  91.     def plugin_on_unpaused(self):
  92.         self.plugin_on_song_started(self.song)
  93.  
  94.     
  95.     def disabled(self):
  96.         if self.status:
  97.             self._set_status(self.config_get(self.CFG_STATUS_SONGLESS))
  98.  
  99.     
  100.     def enabled(self):
  101.         self.song = None
  102.         self.status = ''
  103.  
  104.     
  105.     def PluginPreferences(self, parent):
  106.         outer_vb = Gtk.VBox(spacing = 12)
  107.         vb = Gtk.VBox(spacing = 12)
  108.         hb = Gtk.HBox(spacing = 6)
  109.         entry = UndoEntry()
  110.         entry.set_text(self.config_get(self.CFG_PAT_PLAYING, self.DEFAULT_PAT))
  111.         entry.connect('changed', self.config_entry_changed, self.CFG_PAT_PLAYING)
  112.         lbl = Gtk.Label(label = _('Playing:'))
  113.         entry.set_tooltip_markup(_('Status text when a song is started. Accepts QL Patterns e.g. <tt>%s</tt>') % util.escape('<~artist~title>'))
  114.         lbl.set_mnemonic_widget(entry)
  115.         hb.pack_start(lbl, False, True, 0)
  116.         hb.pack_start(entry, True, True, 0)
  117.         vb.pack_start(hb, True, True, 0)
  118.         hb = Gtk.HBox(spacing = 6)
  119.         entry = UndoEntry()
  120.         entry.set_text(self.config_get(self.CFG_PAT_PAUSED, self.DEFAULT_PAT_PAUSED))
  121.         entry.connect('changed', self.config_entry_changed, self.CFG_PAT_PAUSED)
  122.         lbl = Gtk.Label(label = _('Paused:'))
  123.         entry.set_tooltip_markup(_('Status text when a song is paused. Accepts QL Patterns e.g. <tt>%s</tt>') % util.escape('<~artist~title>'))
  124.         lbl.set_mnemonic_widget(entry)
  125.         hb.pack_start(lbl, False, True, 0)
  126.         hb.pack_start(entry, True, True, 0)
  127.         vb.pack_start(hb, True, True, 0)
  128.         hb = Gtk.HBox(spacing = 6)
  129.         entry = UndoEntry()
  130.         entry.set_text(self.config_get(self.CFG_STATUS_SONGLESS, ''))
  131.         entry.connect('changed', self.config_entry_changed, self.CFG_STATUS_SONGLESS)
  132.         entry.set_tooltip_text(_('Plain text for status when there is no current song'))
  133.         lbl = Gtk.Label(label = _('No song:'))
  134.         lbl.set_mnemonic_widget(entry)
  135.         hb.pack_start(lbl, False, True, 0)
  136.         hb.pack_start(entry, True, True, 0)
  137.         vb.pack_start(hb, True, True, 0)
  138.         frame = qltk.Frame(_('Status Patterns'), child = vb)
  139.         outer_vb.pack_start(frame, False, True, 0)
  140.         return outer_vb
  141.  
  142.  
  143.